package com.tul.exercise.base.thread.base;

/**
 * 继承Thread类,
 * 构造函数中启动线程
 * 该类还可以实现其他接口
 */
public class SimpleThread extends Thread {
    private int countDown = 5;

    private static int threadCount = 0;

    public SimpleThread() {
        // 给线程命名
        super(Integer.toString(++threadCount));

        // 启动线程
        start();
    }

    public String toString() {
        return "#" + getName() + "(" + countDown + "), ";
    }

    /**
     * 线程的任务
     */
    public void run() {
        while (true) {
            System.out.print(this);
            if (--countDown == 0) {
                return;
            }
        }
    }

    public static void main(String[] args) {
        for (int i = 0; i < 5; i++) {
            new SimpleThread();
        }
    }
}
